package com.nitty.cash.loop.ui.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.lib.common.adapter.CommonRecyclerViewAdapter
import com.lib.common.adapter.CommonViewHolderHelper
import com.nitty.cash.loop.R
import org.json.JSONObject

/**
 * NittyCash
 * @Author wwdeng
 * @CreateTime: 2024/8/19 16:42
 * @Annotation：消息列表适配器
 */
class MessageAdapter(recyclerView: RecyclerView?) : CommonRecyclerViewAdapter<JSONObject>(recyclerView) {

    override fun getItemViewType(position: Int): Int {
        val model = getItem(position)
        return when (model.optBoolean("isEmptyView",false)){
            true -> {
                R.layout.ui_page_tab_message_empty
            }
            else -> {
                R.layout.ui_page_tab_message_item
            }
        }
    }

    override fun setItemChildListener(helper: CommonViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.messageItemLayout)
    }

    override fun fillData(helper: CommonViewHolderHelper, position: Int, model: JSONObject) {
        when (model.optBoolean("isEmptyView",false)){
            true -> {//空
            }
            else -> {
                showNittyMessageItemView(helper,position,model)
            }
        }
    }

    private fun showNittyMessageItemView(helper: CommonViewHolderHelper, position: Int, model: JSONObject){
        helper.setText(R.id.textMessageTitle,model.optString("title"))
//        helper.setText(R.id.textTime,model.optString("timeDesc"))
        helper.setText(R.id.textMessageContent,model.optString("content"))

        //不显示未读数量
        helper.setVisibility(R.id.textUnReadCount, View.GONE)

        val imgMessageIcon = helper.getImageView(R.id.imgMessageIcon)
        when(model.optString("type")){
            "REPAY_REMIDER" -> {//还款提醒
                imgMessageIcon.setImageResource(R.mipmap.nitty_message_repay_icon)
            }
            else -> {//AD_MESSAGE  广告推广
                imgMessageIcon.setImageResource(R.mipmap.nitty_message_adv_icon)
            }
        }
    }
}